﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ForexRates.aspx.cs" Inherits="HTComics.Web.Admin.ForexRates" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../Css/jquery-ui-1.8.18.custom.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-ui-1.8.18.custom.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(doOnLoad);

        function doOnLoad() {
            $("#MainContent_btnUpdate").button();
            $("#btnAdminHome").button().click(function () { window.location = "Home.aspx"; return false; });
        }

        function valid() {
            if (!ValFloat($("#MainContent_txtRate").val())) {
                alert("Please enter a valid floating point value in Rate field");
                $("#MainContent_txtRate").focus();
                return false;
            }

            return true;
        }

        function ValFloat(ObjectValue, AllowComma) {
            // Used Internally by ValidateInt, ValidateFloat

            //Returns true if value is a number or is NULL
            //otherwise returns false	

            if (ObjectValue.length == 0) return true;

            //Returns true if value is a number defined as
            //   having an optional leading + or -.
            //   having at most 1 decimal point.
            //   otherwise containing only the characters 0-9.
            var start_format = " .+-0123456789";
            var number_format = " .0123456789";
            if (AllowComma == 1) number_format = number_format + ',';
            var check_char;
            var decimal = false;
            var trailing_blank = false;
            var digits = false;

            //The first character can be + - .  blank or a digit.
            check_char = start_format.indexOf(ObjectValue.charAt(0))
            //Was it a decimal?
            if (check_char == 1)
                decimal = true;
            else if (check_char < 1)
                return false;

            //Remaining characters can be only . or a digit, but only one decimal.
            for (var i = 1; i < ObjectValue.length; i++) {
                check_char = number_format.indexOf(ObjectValue.charAt(i))
                if (check_char < 0)
                    return false;
                else if (check_char == 1) {
                    if (decimal)		// Second decimal.
                        return false;
                    else
                        decimal = true;
                }
                else if (check_char == 0) {
                    if (decimal || digits) trailing_blank = true;
                    // ignore leading blanks
                }
                else if (trailing_blank)
                    return false;
                else
                    digits = true;
            }
            //All tests passed, so...
            return true
        }

        function success() {
            $("#divOK").dialog({
                title: "Success",
                modal: true,
                height: 'auto',
                width: 'auto',
                position: ['center', 'middle']
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Heading" runat="server">
Forex Rates
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
            <div class="section">
                <span class="header">
                    USD to EUR Conversion Rate
                </span>

            <div class="content">      
            
                <table width="100%">
                <tr>
                    <td width="30%" class="labelBold" style="font-size:16px;">Rate</td>
                    <td><input type="text" runat="server" class="textfield" id="txtRate" value=""/></td>                    
                </tr>
                <tr>
                    <td class="labelBold"  style="font-size:16px;">Last Updated</td>
                    <td>
                        <asp:Label ID="lblLastUpdated" runat="server" Text=""></asp:Label></td>                
                </tr>

                </table>          

                <p align="center">
                    <asp:Button ID="btnUpdate" runat="server" Text="Update" 
                        onclick="btnUpdate_Click" onclientclick="return valid();"/>
                    <button id="btnAdminHome">Admin Home</button>
                </p>
            </div>
            </div>

            <div id="divOK" style="display:none;">
                Settings have been updated
            </div>
</asp:Content>
